package chapter1.classLoader;

import java.io.FileNotFoundException;

/**
 * @Author juzipi
 * @Date 2021/5/11 10:36
 * @Info 自定义类加载器
 */
public class CustomClassLoader extends ClassLoader {


    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
        //大概的模型，流程
        try {
            byte[] result = getClassFromCustomPath(name);
            if (result == null){
                throw new FileNotFoundException();
            }
            return defineClass(name,result,0,result.length);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        throw new ClassNotFoundException(name);
    }


    private byte[] getClassFromCustomPath(String name){
        //从自定义路径中加载指定类

        //如果指定路径的字节码文件进行了加密，则需要在此方法中进行解密
        return null;
    }


}
